package com.badibadi.mail;

import java.util.HashMap;
import java.util.Map;

import com.badibadi.mytools.CommonUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.mytools.Dialog;
import com.badibadi.mytools.Dialog.DialogClistener;
import com.badibadi.mytools.Utils;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.layout;
import com.badibadi.uniclubber.R.menu;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 答方：已经回复了问方 问方：填写满意度调查   第一次填写满意度调查
 * 
 * @author Administrator
 *  mhanlder未完成
 */
public class Mail21_22_18Activity extends Mail245Activity {

	AlertDialog al_sheding;
	public Handler mhandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case 1:
				Utils.ExitPrgress(Mail21_22_18Activity.this);
				try {
					Utils.showMessage(Mail21_22_18Activity.this, getResources().getString(R.string.l_net_error));
				} catch (Exception e) {
				}
				break;
			case 2://设定成功
				Utils.ExitPrgress(Mail21_22_18Activity.this);
				try {
					// initListView();
//					initView();
					Utils.showMessage(Mail21_22_18Activity.this, getResources().getString(R.string.l_xb55));
				    Intent intent=new Intent(Mail21_22_18Activity.this,Mail23_25Activity.class);
				    intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);
				    startActivity(intent);
					finish();
					
				} catch (Exception e) {
				}
				break;
			case 3:
				Utils.ExitPrgress(Mail21_22_18Activity.this);
				try {
					Utils.showMessage(Mail21_22_18Activity.this, getResources().getString(R.string.l_xb12));
				} catch (Exception e) {
				}
				break;
			case 4:
				Utils.ExitPrgress(Mail21_22_18Activity.this);
				try {
					Utils.showMessage(Mail21_22_18Activity.this, getResources().getString(R.string.wx_caozuo_false));
				} catch (Exception e) {
				}
				break;

			default:
				break;
			}
		}

	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	protected void DongTaiPeiZhi() {
		// TODO Auto-generated method stub

		if (rank.equals("answerer")) {
			this.findViewById(R.id.delete).setVisibility(View.GONE);
			Button shedingzhixunfei = (Button) this
					.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(R.string.wx_yi_reply));
			shedingzhixunfei.setVisibility(View.VISIBLE);
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Toast t = Toast.makeText(Mail21_22_18Activity.this, getResources().getString(R.string.wx_yi_reply),
							Toast.LENGTH_SHORT);
					t.setGravity(Gravity.CENTER, 0, 0);
					t.show();
				}
			});
			TextView tishi = (TextView) this.findViewById(R.id.tishi);
			tishi.setText(getResources().getString(R.string.wx_fukuan_success_kuohao));
			tishi.setVisibility(View.VISIBLE);
		} else {
			this.findViewById(R.id.delete).setVisibility(View.VISIBLE);
			Button shedingzhixunfei = (Button) this
					.findViewById(R.id.shedingzhixunfei);
			shedingzhixunfei.setText(getResources().getString(R.string.wx_manyidu_diaocha));
			shedingzhixunfei.setVisibility(View.VISIBLE);
			shedingzhixunfei.setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					LayoutInflater inflater = LayoutInflater
							.from(Mail21_22_18Activity.this);
					View view = inflater.inflate(R.layout.manyi_or_bumanyi,
							null);
					// 退款工作日
					TextView refund_time = (TextView) view
							.findViewById(R.id.refund_time);
					refund_time.setText(""
							+ payUserContactShow1Model.getRefund_time());
					// 满意
					Button queding = (Button) view.findViewById(R.id.queding);
					queding.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub

							Dialog d=new Dialog();
							d.CreateDialog(Mail21_22_18Activity.this, getResources().getString(R.string.wx_queding), getResources().getString(R.string.wx_txt_83));
							d.setOnDialogClistener(new DialogClistener() {
								
								@Override
								public void ret() {
									// TODO Auto-generated method stub
									al_sheding.dismiss();
								}
								
								@Override
								public void ok() {
									// TODO Auto-generated method stub
									pay();
									al_sheding.dismiss();
								}
							});
						
						}
					});
					// 不满意
					Button quxiao = (Button) view.findViewById(R.id.quxiao);
					quxiao.setOnClickListener(new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							displeased();
							al_sheding.dismiss();
						}
					});

					al_sheding = new AlertDialog.Builder(
							Mail21_22_18Activity.this).setView(view).show();
				}
			});
			TextView tishi = (TextView) this.findViewById(R.id.tishi);
			tishi.setText(getResources().getString(R.string.wx_yi_reply_kuohao));
			tishi.setVisibility(View.VISIBLE);
		}

	}

	// 不满意操作
	public void displeased() {
		Intent intent=new Intent(Mail21_22_18Activity.this,MailbumanyiActivity.class);
		intent.putExtra("payUserContactShow1Model", payUserContactShow1Model);

//		   
		startActivity(intent);
		finish();
	}

	/**
	 * 有咨询费情况---问方满意答方的回答进行付款操作（需谨慎处理）---POST
	 * 
	 * @param $zhaneniId
	 *            站内信ID
	 * 
	 * @param $uid
	 *            登录用户（问方）
	 * 
	 * @param $reply_id
	 *            回复的是哪一条用户消息ID
	 */
	public void pay() {
		{
                Map<String, Object> map=new HashMap<String, Object>();
                map.put("zhaneniId", payUserContactShow1Model.getZhannei_Id());
                map.put("uid", Utils.getUid(Mail21_22_18Activity.this));
                map.put("reply_id", payUserContactShow1Model.getZhannei_usercontact().get(0).getThisMsgId());
                CommonUtils.CommomPostfunction(Mail21_22_18Activity.this, Constants.BadiUrl_1+"/"+"inform/pay", map,mhandler, 1, 3, 2, 4);
		}
	}

}
